package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.component.Dialog;
import com.github.aloxc.plugin.restplus.component.RequestSetting;
import com.github.aloxc.plugin.restplus.navigator.RestServiceDetail;
import com.github.aloxc.plugin.restplus.utils.StringUtils;
import com.intellij.openapi.util.IconLoader;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 设置url的环境变量及测试用例
 */
public class RequestEnvironmentListener extends MouseAdapter implements ActionListener {
    private RestServiceDetail restServiceDetail;
    public RequestEnvironmentListener(RestServiceDetail restServiceDetail) {
        this.restServiceDetail = restServiceDetail;
    }
    @Override
    public void mouseClicked(MouseEvent e) {
        int height = 640;
        int width = 840;
        if (StringUtils.isNullOrEmpty(restServiceDetail.getUrl())) {
            return;
        }
        RequestSetting setting = new RequestSetting(restServiceDetail.getProject(), restServiceDetail.getUrl(),restServiceDetail.getParentName());
        setting.setMaximumSize(new Dimension(width, height));
        setting.setMinimumSize(new Dimension(width, height));
        setting.setPreferredSize(new Dimension(width, height));
        Dialog dialog = setting.getDialog();
//        com.github.aloxc.plugin.restplus.component.Dialog dialog = new Dialog(null, setting,
//                new Dimension(width, height),
//                new Dimension(width, height),
//                new Dimension(width, height),
//                IconLoader.getIcon("/icons/setting.png"),
//                "Request variate(s) ("+ restServiceDetail.getUrl() +")"
//        );
//        setting.setDialog(dialog);
        dialog.setVisible(true);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        this.mouseClicked(null);
    }
}
